import { ListStore } from '@/store';
import { INITIAL_FORM_QUERY_VALUE, LIST_NAME, LOAD_TASK_LOG_REQUEST_TASK_NAME } from '@/views/task-log/constants';

import { loadTaskList } from './api';

export default class Store extends ListStore {
  formQueryValue = { ...INITIAL_FORM_QUERY_VALUE };

  querying = false;

  // 加载列表
  loadTaskList = async ({ loadAction = 'reset', pageSize: inputPageSize, pageNum: inputPageNum } = {}) => {
    await this.loadList({
      requestTaskName: LOAD_TASK_LOG_REQUEST_TASK_NAME,
      listName: LIST_NAME,
      loadAction,
      pageSize: inputPageSize,
      pageNum: inputPageNum,
      loadDataFunc: async ({ pageSize, pageNum }) => {
        const result = await loadTaskList(this.formQueryValue, { pageSize, pageNum });
        let { rows: data = [], total = 0 } = result || {};
        return { data, total };
      },
    });
  };
  // 查询门店设置
  queryTaskLog = value => {
    this.formQueryValue = value;
    this.loadTaskList({ loadAction: 'pageNumChange', pageNum: 1 });
  };

  // 当前页变更
  pageNumChange = pageNum => {
    this.loadTaskList({ loadAction: 'pageNumChange', pageNum });
  };

  // 每页条数变更
  pageSizeChange = pageSize => {
    this.loadTaskList({ loadAction: 'pageSizeChange', pageSize });
  };

  resetTable = () => {
    this.loadTaskList({ loadAction: 'reset' });
  };

  // 初始加载数据
  init = async () => {};
}
